package com.liwen.kefu.common.exception;

import com.liwen.kefu.common.result.CommonCode;
import com.liwen.kefu.common.result.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: Liwen
 * @createTime: 2024/11/9
 * @description:
 */
@ControllerAdvice(basePackages = {"com.liwen.kefu.controller"})
@Slf4j
public class ExceptionCatch {

    /**
     * 捕获自定义异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public ResponseResult exceptionCatch(CustomException e) {
        CommonCode commonCode = e.getCommonCode();
        log.error("catch exception: {}", e.getMessage());
        return ResponseResult.ERROR(commonCode);
    }
}
